
//
//  YDAHomeTableHeaderView.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/23.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDAHomeTableHeaderView.h"

@interface YDAHomeTableHeaderView()

@property (nonatomic , weak) UIView *upView;

@property (nonatomic , weak) UIView *downView;
//分割线
@property (nonatomic , weak) UIView *lineView;
//图片
@property (nonatomic , weak) UIImageView *cateImage;
//类别
@property (nonatomic , weak) UILabel *cateLabel;

//7*24
@property (nonatomic , weak) SYNoHeightedButton *button1;
//每日要闻
@property (nonatomic , weak) SYNoHeightedButton *button2;

@end


@implementation YDAHomeTableHeaderView


+ (instancetype)headerViewWithTableView:(UITableView *)tableView
{
    
    static NSString *aHomeTableHeaderView = @"YDAHomeTableHeaderView";
    YDAHomeTableHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:aHomeTableHeaderView];
    if (headerView == nil) {
        headerView = [[YDAHomeTableHeaderView alloc] initWithReuseIdentifier:aHomeTableHeaderView];
    }
    return headerView;
}


-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self lineView];
        
        [self cateImage];
        [self cateLabel];

        
    }
    return self;
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
        _lineView = lineView;
    }
    return _lineView;
}
-(UIView *)upView
{
    if (_upView == nil) {
        UIView *upView = [[UIView alloc] init];
        upView.userInteractionEnabled = YES;
        [self.contentView addSubview:upView];
        upView.backgroundColor = [UIColor clearColor];
        [upView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(40)));
            }else{
                make.height.equalTo(@(rate750(40)));
            }
        }];
        
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = CGRectMake(0, 0, LKScreenW, isPhoneX ? rateX812(40) : rate750(40));
        [upView.layer addSublayer:gradientLayer];
        gradientLayer.colors = @[
                                 (__bridge id)[UIColor colorWithHexString:@"FFA16D"].CGColor,
                                 (__bridge id)[UIColor colorWithHexString:mainGray].CGColor,
                                 (__bridge id)[UIColor colorWithHexString:@"FFA16D"].CGColor];
        gradientLayer.locations = @[@0.0,@0.5,@1.0];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);//
        
        _upView = upView;
    }
    return _upView;
}
-(UIView *)downView
{
    if (_downView == nil) {
        UIView *downView = [[UIView alloc] init];
        [self.contentView addSubview:downView];
        downView.backgroundColor = [UIColor clearColor];
        [downView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(40)));
            }else{
                make.height.equalTo(@(rate750(40)));
            }
        }];
        
        _downView = downView;
    }
    return _downView;
}

-(UIImageView *)cateImage
{
    if (_cateImage == nil) {
        UIImageView *cateImage = [[UIImageView alloc] init];
        [self.downView addSubview:cateImage];
        cateImage.image = [UIImage imageNamed:@"homemeirizhangfu"];
        
        [cateImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(rate375(10));
        }];
        
        _cateImage = cateImage;
    }
    return _cateImage;
}

-(UILabel *)cateLabel
{
    if (_cateLabel == nil) {
        UILabel *cateLabel = [[UILabel alloc] init];
        [self.downView addSubview:cateLabel];
        cateLabel.textAlignment = NSTextAlignmentLeft;
        cateLabel.font = [UIFont systemFontOfSize:font15ScreenWRate * LKScreenW];
        cateLabel.text = @"亿点策略涨幅榜";
        cateLabel.textColor = [UIColor colorWithHexString:stockRed];
        
        [cateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(rate375(38));
        }];
        _cateLabel = cateLabel;
    }
    return _cateLabel;
}

-(SYNoHeightedButton *)button1
{
    if (_button1 == nil) {
        SYNoHeightedButton *button1 = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.upView addSubview:button1];
        [button1 setBackgroundColor:[UIColor clearColor]];
        button1.tag = 101;
        [button1 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
        
        [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.top.equalTo(self.upView);
            make.right.equalTo(self.upView.mas_centerX);
            
        }];
        button1.titleLabel.font = [UIFont boldSystemFontOfSize:font16ScreenWRate * LKScreenW];
        [button1 setTitle:@"期股快讯" forState:UIControlStateNormal];
        [button1 setTitleColor:[UIColor colorWithHexString:frenchBlue] forState:UIControlStateNormal];
        _button1 = button1;
    }
    return _button1;
}
-(SYNoHeightedButton *)button2
{
    if (_button2 == nil) {
        SYNoHeightedButton *button2 = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.upView addSubview:button2];
        [button2 setBackgroundColor:[UIColor clearColor]];
        button2.tag = 102;
        [button2 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
        
        [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.top.equalTo(self.upView);
            make.left.equalTo(self.upView.mas_centerX);
            
        }];
        button2.titleLabel.font = [UIFont boldSystemFontOfSize:font16ScreenWRate * LKScreenW];
        [button2 setTitle:@"期股要闻" forState:UIControlStateNormal];
        [button2 setTitleColor:[UIColor colorWithHexString:frenchBlue] forState:UIControlStateNormal];
        _button2 = button2;
    }
    return _button2;
}
-(void)buttonClick:(SYNoHeightedButton *)button
{
    if (button.tag == 101) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(homeTableHeaderView:didSelectedViewStyle:)]) {
            [self.delegate homeTableHeaderView:self didSelectedViewStyle:SYAHomeTableHeaderViewStyleDeafault];
        }
    }else if (button.tag == 102){
        if (self.delegate && [self.delegate respondsToSelector:@selector(homeTableHeaderView:didSelectedViewStyle:)]) {
            [self.delegate homeTableHeaderView:self didSelectedViewStyle:SYAHomeTableHeaderViewStyleDayNews];
        }
    }
    
}

@end
